import { useState, useEffect } from "react"
import { connect } from "dva"

function aa(props: any) {
  let [arr, setCount] = useState([1, 2, 55])
  // console.log('hook：',arr);
  console.log("state:", props)

  // 初始化
  useEffect(() => {
    // console.log('useEffect初始化');
  }, [])

  const clcikEvent = (v: any) => {
    console.log(v)

    props.dispatch({
      type: "index/addNum", // 这里就会触发models层里面effects中和reducers
      payload: {
        num: "打哈沙",
        cc: 5555,
      },
    })
  }

  return (
    <div className="top">
      index/one
      {props.token}
      <div className="bob">num: {props.num} </div>
      <div onClick={() => clcikEvent("")}>点击改变token</div>
    </div>
  )
}

// 字面意思就是，把models的state变成组件的props
function mapStateToProps(state: any) {
  const { num } = state.index // index就是models命名空间名字
  return state.index
}

// 仓库和组件连接
export default connect(mapStateToProps)(aa)
